//@ sourceURL=/static/modules/mapped/mapped.js
var mappedView = new View({
    name: 'mapped',
    init_page() {
        $('#add_btn').click(function () {
            router.to('mapped_add',{type: 'add'})
            return false;
        });
    }
});
let selectMapperUrl = '/mapper/selectMapper'          //查询列表
let deleteMapperUrl = '/mapper/deleteMapper'          //删除
/**
 * 方法
 */
mappedView.fn = {
    edit (e) {
        var id = $(e).data('id');
        router.to('mapped_add',{type: 'edit',itemId :id})
    },
    delete (e) {
        let id = $(e).data('id');
        swal($.po('sweetalert', {
            title: "确定要删除该员工吗？",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: '#DD6B55',
            confirmButtonText: '删除',
            cancelButtonText: "取消",
            closeOnConfirm: false,
        }), function (isConfirm) {
            if (isConfirm) {
                wdAjax.get({
                    url: deleteMapperUrl + '?id=' + id,
                    success: function (data) {
                        alertify.success('删除成功');
                        swal.close();
                        mappedView.plugins.mapped_list.api.draw();
                        // mappedView.plugins.mapped_list.refresh();
                    }
                })
            }
        });
    },
    render: {
        operation(data, type) {
            var html = '<button class="btn btn-primary margin-right-10 grid-delete-btn" data-name="' + data.mname + '" data-id="' + data.id + '" type="button" onClick="mappedView.fn.edit(this)" >编辑</button>'+
                '<button class="btn btn-primary margin-right-10 grid-delete-btn" data-name="' + data.mname + '" data-id="' + data.id + '" type="button" onClick="mappedView.fn.delete(this)" >删除</button>'
            return html;
        }
    }
}
/**
 * 事件
 */
mappedView._event = () => {

}

/**
 * 绑定插件
 */
mappedView.use(new Table({
    name: 'mapped_list',
    selector: '#mapped_list',
    url: selectMapperUrl,
    search_btn: "#search_btn",
    callback: function () {

    }
}))